<template>
  <div class="right-board">
    <el-tabs v-model="currentTab" class="center-tabs">
      <el-tab-pane :label="$t('zuJianShuXing')" name="field" />
      <el-tab-pane :label="$t('biaoDanShuXing')" name="form" />
    </el-tabs>
    <div class="field-box">
      <!-- <a class="document-link" target="_blank" :href="documentLink" title="查看组件文档">
        <i class="el-icon-link" />
      </a> -->
      <el-scrollbar class="right-scrollbar">
        <!-- 组件属性 -->
        <el-form v-show="currentTab === 'field' && showField" size="small" label-width="90px">
          <el-form-item v-if="activeData.__config__.changeTag" :label="$t('zuJianLeiXing')">
            <el-select
              v-model="activeData.__config__.tagIcon"
              :placeholder="$t('qingXuanZeZuJianLeiXing')"
              :style="{ width: '100%' }"
              @change="tagChange"
            >
              <el-option-group v-for="group in tagList" :key="group.label" :label="group.label">
                <el-option
                  v-for="item in group.options"
                  :key="item.__config__.label"
                  :label="item.__config__.label"
                  :value="item.__config__.tagIcon"
                >
                  <svg-icon class="node-icon" :icon-class="item.__config__.tagIcon" />
                  <span> {{ item.__config__.label }}</span>
                </el-option>
              </el-option-group>
            </el-select>
          </el-form-item>
          <el-form-item v-if="activeData.__vModel__ !== undefined" :label="$t('ziDuanMing')">
            <el-input v-model="activeData.__vModel__" :placeholder="$t('qingShuRuZiDuanMing')+'（v-model）'" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.componentName !== undefined" :label="$t('zuJianMing')">
            {{ activeData.__config__.componentName }}
          </el-form-item>
          <el-form-item v-if="activeData.__config__.label !== undefined" :label="$t('biaoTi')">
            <el-input v-model="activeData.__config__.label" :placeholder="$t('qingShuRuBiaoTi')" />
          </el-form-item>
          <el-form-item v-if="activeData.placeholder !== undefined" :label="$t('zhanWeiTiShi')">
            <el-input v-model="activeData.placeholder" :placeholder="$t('qingShuRuZhanWeiTiShi')" />
          </el-form-item>
          <el-form-item v-if="activeData['start-placeholder'] !== undefined" :label="$t('kaiShiZhanWei')">
            <el-input v-model="activeData['start-placeholder']" :placeholder="$t('qingShuRuZhanWeiTiShi')" />
          </el-form-item>
          <el-form-item v-if="activeData['end-placeholder'] !== undefined" :label="$t('jieShuZhanWei')">
            <el-input v-model="activeData['end-placeholder']" :placeholder="$t('qingShuRuZhanWeiTiShi')" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.span !== undefined" :label="$t('biaoDanZhaGe')">
            <el-slider
              v-model="activeData.__config__.span"
              :max="24"
              :min="1"
              :marks="{ 12: '' }"
              @change="spanChange"
            />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.layout === 'rowFormItem'" :label="$t('zhaGeJianGe')">
            <el-input-number v-model="activeData.gutter" :min="0" :placeholder="$t('zhaGeJianGe')" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.layout === 'rowFormItem'" :label="$t('buJuMoShi')">
            <el-radio-group v-model="activeData.type">
              <el-radio-button label="default" />
              <el-radio-button label="flex" />
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="activeData.justify !== undefined && activeData.type === 'flex'" :label="$t('shuiPingPaiLie')">
            <el-select v-model="activeData.justify" :placeholder="$t('qingXuanZeShuiPingPaiLie')" :style="{ width: '100%' }">
              <el-option v-for="(item, index) in justifyOptions" :key="index" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item v-if="activeData.align !== undefined && activeData.type === 'flex'" :label="$t('chuiZhiPaiLie')">
            <el-radio-group v-model="activeData.align">
              <el-radio-button label="top" />
              <el-radio-button label="middle" />
              <el-radio-button label="bottom" />
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="activeData.__config__.labelWidth !== undefined" :label="$t('biaoQianKuanDu')">
            <el-input v-model.number="activeData.__config__.labelWidth" type="number" :placeholder="$t('qingShuRuBiaoQianKuanDu')" />
          </el-form-item>
          <el-form-item v-if="activeData.style && activeData.style.width !== undefined" :label="$t('zuJianKuanDu')">
            <el-input v-model="activeData.style.width" :placeholder="$t('qingShuRuZuJianKuanDu')" clearable />
          </el-form-item>
          <el-form-item v-if="activeData.__vModel__ !== undefined" :label="$t('moRenZhi')">
            <el-input
              :value="setDefaultValue(activeData.__config__.defaultValue)"
              :placeholder="$t('qingShuRuMoRenZhi')"
              @input="onDefaultValueInput"
            />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-checkbox-group'" :label="$t('zhiShaoYingXuan')">
            <el-input-number
              :value="activeData.min"
              :min="0"
              :placeholder="$t('zhiShaoYingXuan')"
              @input="$set(activeData, 'min', $event ? $event : undefined)"
            />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-checkbox-group'" :label="$t('zuiDuoKeXuan')">
            <el-input-number
              :value="activeData.max"
              :min="0"
              :placeholder="$t('zuiDuoKeXuan')"
              @input="$set(activeData, 'max', $event ? $event : undefined)"
            />
          </el-form-item>
          <el-form-item v-if="activeData.__slot__ && activeData.__slot__.prepend !== undefined" :label="$t('qianZhui')">
            <el-input v-model="activeData.__slot__.prepend" :placeholder="$t('qingShuRuQianZhui')" />
          </el-form-item>
          <el-form-item v-if="activeData.__slot__ && activeData.__slot__.append !== undefined" :label="$t('houZhui')">
            <el-input v-model="activeData.__slot__.append" :placeholder="$t('qingShuRuHouZhui')" />
          </el-form-item>
          <el-form-item v-if="activeData['prefix-icon'] !== undefined" :label="$t('qianTuBiao')">
            <el-input v-model="activeData['prefix-icon']" :placeholder="$t('qingShuRuQianTuBiaoMingCheng')">
              <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('prefix-icon')"> {{ $t('xuanZe') }} </el-button>
            </el-input>
          </el-form-item>
          <el-form-item v-if="activeData['suffix-icon'] !== undefined" :label="$t('houTuBiao')">
            <el-input v-model="activeData['suffix-icon']" :placeholder="$t('qingShuRuHouTuBiaoMingCheng')">
              <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('suffix-icon')"> {{ $t('xuanZe') }} </el-button>
            </el-input>
          </el-form-item>
          <el-form-item
            v-if="activeData['icon'] !== undefined && activeData.__config__.tag === 'el-button'"
            :label="$t('anNiuTuBiao')"
          >
            <el-input v-model="activeData['icon']" :placeholder="$t('qingShuRuAnNiuTuBiaoMingCheng')">
              <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('icon')"> {{ $t('xuanZe') }} </el-button>
            </el-input>
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" :label="$t('xuanXiangFenGeFu')">
            <el-input v-model="activeData.separator" :placeholder="$t('qingShuRuXuanXiangFenGeFu')" />
          </el-form-item>
          <el-form-item v-if="activeData.autosize !== undefined" :label="$t('zuiXiaoHangShu')">
            <el-input-number v-model="activeData.autosize.minRows" :min="1" :placeholder="$t('zuiXiaoHangShu')" />
          </el-form-item>
          <el-form-item v-if="activeData.autosize !== undefined" :label="$t('zuiDaHangShu')">
            <el-input-number v-model="activeData.autosize.maxRows" :min="1" :placeholder="$t('zuiDaHangShu')" />
          </el-form-item>
          <el-form-item v-if="isShowMin" :label="$t('zuiXiaoZhi')">
            <el-input-number v-model="activeData.min" :placeholder="$t('zuiXiaoZhi')" />
          </el-form-item>
          <el-form-item v-if="isShowMax" :label="$t('zuiDaZhi')">
            <el-input-number v-model="activeData.max" :placeholder="$t('zuiDaZhi')" />
          </el-form-item>
          <el-form-item v-if="activeData.height !== undefined" :label="$t('zuJianGaoDu')">
            <el-input-number v-model="activeData.height" :placeholder="$t('gaoDu')" @input="changeRenderKey" />
          </el-form-item>
          <el-form-item v-if="isShowStep" :label="$t('buChang')">
            <el-input-number v-model="activeData.step" :placeholder="$t('buShu')" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" :label="$t('jingDu')">
            <el-input-number v-model="activeData.precision" :min="0" :placeholder="$t('jingDu')" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" :label="$t('anNiuWeiZhi')">
            <el-radio-group v-model="activeData['controls-position']">
              <el-radio-button label=""> {{ $t('moRen') }} </el-radio-button>
              <el-radio-button label="right"> {{ $t('youCe') }} </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="activeData.maxlength !== undefined" :label="$t('zuiDuoShuRu')">
            <el-input v-model="activeData.maxlength" :placeholder="$t('qingShuRuZiFuChangDu')">
              <template slot="append"> {{ $t('geZiFu') }} </template>
            </el-input>
          </el-form-item>
          <el-form-item v-if="activeData['active-text'] !== undefined" :label="$t('kaiQiTiShi')">
            <el-input v-model="activeData['active-text']" :placeholder="$t('qingShuRuKaiQiTiShi')" />
          </el-form-item>
          <el-form-item v-if="activeData['inactive-text'] !== undefined" :label="$t('guanBiTiShi')">
            <el-input v-model="activeData['inactive-text']" :placeholder="$t('qingShuRuGuanBiTiShi')" />
          </el-form-item>
          <el-form-item v-if="activeData['active-value'] !== undefined" :label="$t('kaiQiZhi')">
            <el-input
              :value="setDefaultValue(activeData['active-value'])"
              :placeholder="$t('qingShuRuKaiQiZhi')"
              @input="onSwitchValueInput($event, 'active-value')"
            />
          </el-form-item>
          <el-form-item v-if="activeData['inactive-value'] !== undefined" :label="$t('guanBiZhi')">
            <el-input
              :value="setDefaultValue(activeData['inactive-value'])"
              :placeholder="$t('qingShuRuGuanBiZhi')"
              @input="onSwitchValueInput($event, 'inactive-value')"
            />
          </el-form-item>
          <el-form-item
            v-if="activeData.type !== undefined && 'el-date-picker' === activeData.__config__.tag"
            :label="$t('shiJianLeiXing')"
          >
            <el-select
              v-model="activeData.type"
              :placeholder="$t('qingXuanZeShiJianLeiXing')"
              :style="{ width: '100%' }"
              @change="dateTypeChange"
            >
              <el-option v-for="(item, index) in dateOptions" :key="index" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item v-if="activeData.name !== undefined" :label="$t('wenJianZiDuanMing')">
            <el-input v-model="activeData.name" :placeholder="$t('qingShuRuShangChuanWenJianZiDuanMing')" />
          </el-form-item>
          <el-form-item v-if="activeData.accept === 'image'" :label="$t('wenJianLeiXing')">
            <span>{{ $t('tuPian') }}</span>
          </el-form-item>
          <el-form-item v-if="activeData.accept !== undefined && activeData.accept !== 'image'" :label="$t('wenJianLeiXing')">
            <el-select v-model="activeData.accept" :placeholder="$t('qingXuanZeWenJianLeiXing')" :style="{ width: '100%' }" clearable>
              <el-option :label="$t('shiPin')" value="video/*" />
              <el-option :label="$t('yinPin')" value="audio/*" />
              <el-option label="excel" value=".xls,.xlsx" />
              <el-option label="word" value=".doc,.docx" />
              <el-option label="pdf" value=".pdf" />
              <el-option label="txt" value=".txt" />
            </el-select>
          </el-form-item>
          <el-form-item v-if="activeData.__config__.fileSize !== undefined" :label="$t('wenJianDaXiao')">
            <el-input v-model.number="activeData.__config__.fileSize" :placeholder="$t('qingShuRuWenJianDaXiao')">
              <el-select slot="append" v-model="activeData.__config__.sizeUnit" :style="{ width: '66px' }">
                <el-option label="KB" value="KB" />
                <el-option label="MB" value="MB" />
                <el-option label="GB" value="GB" />
              </el-select>
            </el-input>
          </el-form-item>
          <el-form-item v-if="activeData.action !== undefined" :label="$t('shangChuanDiZhi')">
            <el-input v-model="activeData.action" :placeholder="$t('qingShuRuShangChuanDiZhi')" clearable />
          </el-form-item>
          <el-form-item v-if="activeData['list-type'] !== undefined" :label="$t('lieBiaoLeiXing')">
            <el-radio-group v-model="activeData['list-type']" size="small">
              <el-radio-button label="text"> text </el-radio-button>
              <el-radio-button label="picture"> picture </el-radio-button>
              <el-radio-button label="picture-card"> picture-card </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            v-if="activeData.type !== undefined && activeData.__config__.tag === 'el-button'"
            :label="$t('anNiuLeiXing')"
          >
            <el-select v-model="activeData.type" :style="{ width: '100%' }">
              <el-option label="primary" value="primary" />
              <el-option label="success" value="success" />
              <el-option label="warning" value="warning" />
              <el-option label="danger" value="danger" />
              <el-option label="info" value="info" />
              <el-option label="text" value="text" />
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="activeData.__config__.buttonText !== undefined"
            v-show="'picture-card' !== activeData['list-type']"
            :label="$t('anNiuWenZi')"
          >
            <el-input v-model="activeData.__config__.buttonText" :placeholder="$t('qingShuRuAnNiuWenZi')" />
          </el-form-item>
          <el-form-item v-if="activeData['range-separator'] !== undefined" :label="$t('fenGeFu')">
            <el-input v-model="activeData['range-separator']" :placeholder="$t('qingShuRuFenGeFu')" />
          </el-form-item>
          <el-form-item v-if="activeData['picker-options'] !== undefined" :label="$t('shiJianDuan')">
            <el-input v-model="activeData['picker-options'].selectableRange" :placeholder="$t('qingShuRuShiJianDuan')" />
          </el-form-item>
          <el-form-item v-if="activeData.format !== undefined" :label="$t('shiJianGeShi')">
            <el-input :value="activeData.format" :placeholder="$t('qingShuRuShiJianGeShi')" @input="setTimeValue($event)" />
          </el-form-item>
          <template v-if="['el-checkbox-group', 'el-radio-group', 'el-select'].indexOf(activeData.__config__.tag) > -1">
            <el-divider>{{ $t('xuanXiang') }}</el-divider>
            <draggable :list="activeData.__slot__.options" :animation="340" group="selectItem" handle=".option-drag">
              <div v-for="(item, index) in activeData.__slot__.options" :key="index" class="select-item">
                <div class="select-line-icon option-drag">
                  <i class="el-icon-s-operation" />
                </div>
                <el-input v-model="item.label" :placeholder="$t('xuanXiangMing')" size="small" />
                <el-input :placeholder="$t('xuanXiangZhi')" size="small" :value="item.value" @input="setOptionValue(item, $event)" />
                <div class="close-btn select-line-icon" @click="activeData.__slot__.options.splice(index, 1)">
                  <i class="el-icon-remove-outline" />
                </div>
              </div>
            </draggable>
            <div style="margin-left: 20px">
              <el-button
                style="padding-bottom: 0"
                icon="el-icon-circle-plus-outline"
                type="text"
                @click="addSelectItem"
              >
                {{ $t('tianJiaXuanXiang') }}
              </el-button>
            </div>
            <el-divider />
          </template>

          <template v-if="['el-cascader'].indexOf(activeData.__config__.tag) > -1">
            <el-divider>{{ $t('xuanXiang') }}</el-divider>
            <el-form-item :label="$t('shuJuLeiXing')">
              <el-radio-group v-model="activeData.__config__.dataType" size="small">
                <el-radio-button label="dynamic"> {{ $t('dongTaiShuJu') }} </el-radio-button>
                <el-radio-button label="static"> {{ $t('jingTaiShuJu') }} </el-radio-button>
              </el-radio-group>
            </el-form-item>

            <template v-if="activeData.__config__.dataType === 'dynamic'">
              <el-form-item :label="$t('biaoQianJianMing')">
                <el-input v-model="activeData.props.props.label" :placeholder="$t('qingShuRuBiaoQianJianMing')" />
              </el-form-item>
              <el-form-item :label="$t('zhiJianMing')">
                <el-input v-model="activeData.props.props.value" :placeholder="$t('qingShuRuZhiJianMing')" />
              </el-form-item>
              <el-form-item :label="$t('ziJiJianMing')">
                <el-input v-model="activeData.props.props.children" :placeholder="$t('qingShuRuZiJiJianMing')" />
              </el-form-item>
            </template>

            <!-- 级联选择静态树 -->
            <el-tree
              v-if="activeData.__config__.dataType === 'static'"
              draggable
              :data="activeData.options"
              node-key="id"
              :expand-on-click-node="false"
              :render-content="renderContent"
            />
            <div v-if="activeData.__config__.dataType === 'static'" style="margin-left: 20px">
              <el-button style="padding-bottom: 0" icon="el-icon-circle-plus-outline" type="text" @click="addTreeItem">
                {{ $t('tianJiaFuJi') }}
              </el-button>
            </div>
            <el-divider />
          </template>

          <el-form-item v-if="activeData.__config__.optionType !== undefined" :label="$t('xuanXiangYangShi')">
            <el-radio-group v-model="activeData.__config__.optionType">
              <el-radio-button label="default"> {{ $t('moRen') }} </el-radio-button>
              <el-radio-button label="button"> {{ $t('anNiu') }} </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="activeData['active-color'] !== undefined" :label="$t('kaiQiYanSe')">
            <el-color-picker v-model="activeData['active-color']" />
          </el-form-item>
          <el-form-item v-if="activeData['inactive-color'] !== undefined" :label="$t('guanBiYanSe')">
            <el-color-picker v-model="activeData['inactive-color']" />
          </el-form-item>

          <el-form-item
            v-if="activeData.__config__.showLabel !== undefined && activeData.__config__.labelWidth !== undefined"
            :label="$t('xianShiBiaoQian')"
          >
            <el-switch v-model="activeData.__config__.showLabel" />
          </el-form-item>
          <el-form-item v-if="activeData.branding !== undefined" :label="$t('pinPaiLaoYin')">
            <el-switch v-model="activeData.branding" @input="changeRenderKey" />
          </el-form-item>
          <el-form-item v-if="activeData['allow-half'] !== undefined" :label="$t('yunXuBanXuan')">
            <el-switch v-model="activeData['allow-half']" />
          </el-form-item>
          <el-form-item v-if="activeData['show-text'] !== undefined" :label="$t('fuZhuWenZi')">
            <el-switch v-model="activeData['show-text']" @change="rateTextChange" />
          </el-form-item>
          <el-form-item v-if="activeData['show-score'] !== undefined" :label="$t('xianShiFenShu')">
            <el-switch v-model="activeData['show-score']" @change="rateScoreChange" />
          </el-form-item>
          <el-form-item v-if="activeData['show-stops'] !== undefined" :label="$t('xianShiJianDuanDian')">
            <el-switch v-model="activeData['show-stops']" />
          </el-form-item>
          <el-form-item v-if="activeData.range !== undefined" :label="$t('fanWeiXuanZe')">
            <el-switch v-model="activeData.range" @change="rangeChange" />
          </el-form-item>
          <el-form-item
            v-if="activeData.__config__.border !== undefined && activeData.__config__.optionType === 'default'"
            :label="$t('shiFouDaiBianKuang')"
          >
            <el-switch v-model="activeData.__config__.border" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-color-picker'" :label="$t('yanSeGeShi')">
            <el-select
              v-model="activeData['color-format']"
              :placeholder="$t('qingXuanZeYanSeGeShi')"
              :style="{ width: '100%' }"
              clearable
              @change="colorFormatChange"
            >
              <el-option
                v-for="(item, index) in colorFormatOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="
              activeData.size !== undefined &&
              (activeData.__config__.optionType === 'button' ||
                activeData.__config__.border ||
                activeData.__config__.tag === 'el-color-picker' ||
                activeData.__config__.tag === 'el-button')
            "
            :label="$t('zuJianChiCun')"
          >
            <el-radio-group v-model="activeData.size">
              <el-radio-button label="medium"> {{ $t('zhongDeng') }} </el-radio-button>
              <el-radio-button label="small"> {{ $t('jiaoXiao') }} </el-radio-button>
              <el-radio-button label="mini"> {{ $t('miNi') }} </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="activeData['show-word-limit'] !== undefined" :label="$t('shuRuTongJi')">
            <el-switch v-model="activeData['show-word-limit']" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" :label="$t('yanGeBuShu')">
            <el-switch v-model="activeData['step-strictly']" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" :label="$t('shiFouDuoXuan')">
            <el-switch v-model="activeData.props.props.multiple" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" :label="$t('zhanShiQuanLuJing')">
            <el-switch v-model="activeData['show-all-levels']" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" :label="$t('keFouShaiXuan')">
            <el-switch v-model="activeData.filterable" />
          </el-form-item>
          <el-form-item v-if="activeData.clearable !== undefined" :label="$t('nengFouQingKong')">
            <el-switch v-model="activeData.clearable" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.showTip !== undefined" :label="$t('xianShiTiShi')">
            <el-switch v-model="activeData.__config__.showTip" />
          </el-form-item>
          <el-form-item
            v-if="activeData.__config__.tag === 'el-upload' || activeData.__config__.tag === 'self-upload'"
            :label="$t('duoXuanWenJian')"
          >
            <el-switch v-model="activeData.multiple" />
          </el-form-item>
          <el-form-item v-if="activeData['auto-upload'] !== undefined" :label="$t('ziDongShangChuan')">
            <el-switch v-model="activeData['auto-upload']" />
          </el-form-item>
          <el-form-item v-if="activeData.readonly !== undefined" :label="$t('shiFouZhiDu')">
            <el-switch v-model="activeData.readonly" />
          </el-form-item>
          <el-form-item v-if="activeData.disabled !== undefined" :label="$t('shiFouJinYong')">
            <el-switch v-model="activeData.disabled" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-select'" :label="$t('nengFouSouSuo')">
            <el-switch v-model="activeData.filterable" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tag === 'el-select'" :label="$t('shiFouDuoXuan')">
            <el-switch v-model="activeData.multiple" @change="multipleChange" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.required !== undefined" :label="$t('shiFouBiTian')">
            <el-switch v-model="activeData.__config__.required" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tips !== undefined" :label="$t('kaiQiMiaoShu')">
            <el-switch v-model="activeData.__config__.tips" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tips" :label="$t('miaoShuNeiRong')">
            <el-input v-model="activeData.__config__.tipsDesc" :placeholder="$t('qingShuRuMiaoShu')" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tips" :label="$t('miaoShuLianJie')">
            <el-switch v-model="activeData.__config__.tipsIsLink" />
          </el-form-item>
          <el-form-item v-if="activeData.__config__.tipsIsLink" :label="$t('lianJieDiZhi')">
            <el-input v-model="activeData.__config__.tipsLink" :placeholder="$t('qingShuRuLianJieDiZhi')" />
          </el-form-item>
          <!-- <el-form-item v-if="activeData.__config__.bindInput !== undefined" label="绑定输入">
            <el-switch v-model="activeData.__config__.bindInput" />
          </el-form-item>
           <el-form-item v-if="activeData.__config__.bindInput" label="绑定内容">
            <el-input v-model="activeData.__config__.bindValve" placeholder="请输入内容" />
          </el-form-item> -->
          <template v-if="activeData.__config__.layoutTree">
            <el-divider>{{ $t('buJuJieGouShu') }}</el-divider>
            <el-tree
              :data="[activeData.__config__]"
              :props="layoutTreeProps"
              node-key="renderKey"
              default-expand-all
              draggable
            >
              <span slot-scope="{ node, data }">
                <span class="node-label">
                  <svg-icon class="node-icon" :icon-class="data.__config__ ? data.__config__.tagIcon : data.tagIcon" />
                  {{ node.label }}
                </span>
              </span>
            </el-tree>
          </template>

          <template v-if="activeData.__config__.layout === 'colFormItem'">
            <el-divider>{{ $t('zhengZeXiaoYan') }}</el-divider>
            <div v-for="(item, index) in activeData.__config__.regList" :key="index" class="reg-item">
              <span class="close-btn" @click="activeData.__config__.regList.splice(index, 1)">
                <i class="el-icon-close" />
              </span>
              <el-form-item :label="$t('biaoDaShi')">
                <el-input v-model="item.pattern" :placeholder="$t('qingShuRuZhengZe')" />
              </el-form-item>
              <el-form-item :label="$t('cuoWuTiShi')" style="margin-bottom: 0">
                <el-input v-model="item.message" :placeholder="$t('qingShuRuCuoWuTiShi')" />
              </el-form-item>
            </div>
            <div style="margin-left: 20px">
              <el-button icon="el-icon-circle-plus-outline" type="text" @click="addReg"> {{ $t('tianJiaGuiZe') }} </el-button>
            </div>
          </template>
        </el-form>
        <!-- 表单属性 -->
        <el-form v-show="currentTab === 'form'" size="small" label-width="90px">
          <el-form-item :label="$t('biaoDanMing')">
            <el-input v-model="formConf.formRef" :placeholder="$t('qingShuRuBiaoDanMing')+'（ref）'" />
          </el-form-item>
          <el-form-item :label="$t('biaoDanMoXing')">
            <el-input v-model="formConf.formModel" :placeholder="$t('qingShuRuShuJuMoXing')" />
          </el-form-item>
          <el-form-item :label="$t('xiaoYanMoXing')">
            <el-input v-model="formConf.formRules" :placeholder="$t('qingShuRuXiaoYanMoXing')" />
          </el-form-item>
          <el-form-item :label="$t('biaoDanChiCun')">
            <el-radio-group v-model="formConf.size">
              <el-radio-button label="medium"> {{ $t('zhongDeng') }} </el-radio-button>
              <el-radio-button label="small"> {{ $t('jiaoXiao') }} </el-radio-button>
              <el-radio-button label="mini"> {{ $t('miNi') }} </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item :label="$t('biaoQianDuiQi')">
            <el-radio-group v-model="formConf.labelPosition">
              <el-radio-button label="left"> {{ $t('zuoDuiQi') }} </el-radio-button>
              <el-radio-button label="right"> {{ $t('youDuiQi') }} </el-radio-button>
              <el-radio-button label="top"> {{ $t('dingBuDuiQi') }} </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item :label="$t('biaoQianKuanDu')">
            <el-input v-model.number="formConf.labelWidth" type="number" :placeholder="$t('qingShuRuBiaoQianKuanDu')" />
          </el-form-item>
          <el-form-item :label="$t('zhaGeJianGe')">
            <el-input-number v-model="formConf.gutter" :min="0" :placeholder="$t('zhaGeJianGe')" />
          </el-form-item>
          <el-form-item :label="$t('jinYongBiaoDan')">
            <el-switch v-model="formConf.disabled" />
          </el-form-item>
          <el-form-item :label="$t('biaoDanAnNiu')">
            <el-switch v-model="formConf.formBtns" />
          </el-form-item>
          <el-form-item :label="$t('xianShiWeiXuanZhongZuJianBianKuang')">
            <el-switch v-model="formConf.unFocusedComponentBorder" />
          </el-form-item>
        </el-form>
      </el-scrollbar>
    </div>

    <treeNode-dialog :visible.sync="dialogVisible" :title="$t('tianJiaXuanXiang')" @commit="addNode" />
    <icons-dialog :visible.sync="iconsVisible" :current="activeData[currentIconModel]" @select="setIcon" />
  </div>
</template>

<script>
import { isArray } from 'util';
import TreeNodeDialog from './TreeNodeDialog';
import { isNumberStr } from '../utils/index';
import IconsDialog from './IconsDialog';
import {
  inputComponents,
  selectComponents,
  layoutComponents,
} from '@/components/FormGenerator/components/generator/config';
import { saveFormConf } from '../utils/db';


export default {
  components: {
    TreeNodeDialog,
    IconsDialog,
  },
  props: ['showField', 'activeData', 'formConf'],
  data() {
    return {
      currentTab: 'field',
      currentNode: null,
      dialogVisible: false,
      iconsVisible: false,
      currentIconModel: null,
      dateTypeOptions: [
        {
          label: this.$t('ri'),
          value: 'date',
        },
        {
          label: this.$t('zhou'),
          value: 'week',
        },
        {
          label: this.$t('yue'),
          value: 'month',
        },
        {
          label: this.$t('nian'),
          value: 'year',
        },
        {
          label: this.$t('riQiShiJian'),
          value: 'datetime',
        },
      ],
      dateRangeTypeOptions: [
        {
          label: this.$t('riQiFanWei'),
          value: 'daterange',
        },
        {
          label: this.$t('yueFanWei'),
          value: 'monthrange',
        },
        {
          label: this.$t('riQiShiJianFanWei'),
          value: 'datetimerange',
        },
      ],
      colorFormatOptions: [
        {
          label: 'hex',
          value: 'hex',
        },
        {
          label: 'rgb',
          value: 'rgb',
        },
        {
          label: 'rgba',
          value: 'rgba',
        },
        {
          label: 'hsv',
          value: 'hsv',
        },
        {
          label: 'hsl',
          value: 'hsl',
        },
      ],
      justifyOptions: [
        {
          label: 'start',
          value: 'start',
        },
        {
          label: 'end',
          value: 'end',
        },
        {
          label: 'center',
          value: 'center',
        },
        {
          label: 'space-around',
          value: 'space-around',
        },
        {
          label: 'space-between',
          value: 'space-between',
        },
      ],
      layoutTreeProps: {
        label(data, node) {
          const config = data.__config__;
          return data.componentName || `${config.label}: ${data.__vModel__}`;
        },
      },
      dateTimeFormat:{
        date: 'yyyy-MM-dd',
        week: this.$t('yyyyDiWwZhou'),
        month: 'yyyy-MM',
        year: 'yyyy',
        datetime: 'yyyy-MM-dd HH:mm:ss',
        daterange: 'yyyy-MM-dd',
        monthrange: 'yyyy-MM',
        datetimerange: 'yyyy-MM-dd HH:mm:ss',
      }
    };
  },
  computed: {
    // documentLink() {
    //   return (
    //     this.activeData.__config__.document
    //     || 'https://element.eleme.cn/#/zh-CN/component/installation'
    //   )
    // },
    dateOptions() {
      if (this.activeData.type !== undefined && this.activeData.__config__.tag === 'el-date-picker') {
        if (this.activeData['start-placeholder'] === undefined) {
          return this.dateTypeOptions;
        }
        return this.dateRangeTypeOptions;
      }
      return [];
    },
    tagList() {
      return [
        {
          label: this.$t('shuRuXingZuJian'),
          options: inputComponents,
        },
        {
          label: this.$t('xuanZeXingZuJian'),
          options: selectComponents,
        },
      ];
    },
    activeTag() {
      return this.activeData.__config__.tag;
    },
    isShowMin() {
      return ['el-input-number', 'el-slider'].indexOf(this.activeTag) > -1;
    },
    isShowMax() {
      return ['el-input-number', 'el-slider', 'el-rate'].indexOf(this.activeTag) > -1;
    },
    isShowStep() {
      return ['el-input-number', 'el-slider'].indexOf(this.activeTag) > -1;
    },
  },
  watch: {
    formConf: {
      handler(val) {
        saveFormConf(val);
      },
      deep: true,
    },
  },
  mounted() {
    saveFormConf(this.formConf);
  },
  methods: {
    addReg() {
      this.activeData.__config__.regList.push({
        pattern: '',
        message: '',
      });
    },
    addSelectItem() {
      this.activeData.__slot__.options.push({
        label: '',
        value: '',
      });
    },
    addTreeItem() {
      ++this.idGlobal;
      this.dialogVisible = true;
      this.currentNode = this.activeData.options;
    },
    renderContent(h, { node, data, store }) {
      return (
        <div class="custom-tree-node">
          <span>{node.label}</span>
          <span class="node-operation">
            <i on-click={() => this.append(data)} class="el-icon-plus" title="{this.$t('tianJia')}"></i>
            <i on-click={() => this.remove(node, data)} class="el-icon-delete" title="{this.$t('shanChu')}"></i>
          </span>
        </div>
      );
    },
    append(data) {
      if (!data.children) {
        this.$set(data, 'children', []);
      }
      this.dialogVisible = true;
      this.currentNode = data.children;
    },
    remove(node, data) {
      this.activeData.__config__.defaultValue = []; // 避免删除时报错
      const { parent } = node;
      const children = parent.data.children || parent.data;
      const index = children.findIndex((d) => d.id === data.id);
      children.splice(index, 1);
    },
    addNode(data) {
      this.currentNode.push(data);
    },
    setOptionValue(item, val) {
      item.value = isNumberStr(val) ? +val : val;
    },
    setDefaultValue(val) {
      if (Array.isArray(val)) {
        return val.join(',');
      }
      // if (['string', 'number'].indexOf(typeof val) > -1) {
      //   return val
      // }
      if (typeof val === 'boolean') {
        return `${val}`;
      }
      return val;
    },
    onDefaultValueInput(str) {
      if (isArray(this.activeData.__config__.defaultValue)) {
        // 数组
        this.$set(
          this.activeData.__config__,
          'defaultValue',
          str.split(',').map((val) => (isNumberStr(val) ? +val : val)),
        );
      } else if (['true', 'false'].indexOf(str) > -1) {
        // 布尔
        this.$set(this.activeData.__config__, 'defaultValue', JSON.parse(str));
      } else {
        // 字符串和数字
        this.$set(this.activeData.__config__, 'defaultValue', isNumberStr(str) ? +str : str);
      }
    },
    onSwitchValueInput(val, name) {
      if (['true', 'false'].indexOf(val) > -1) {
        this.$set(this.activeData, name, JSON.parse(val));
      } else {
        this.$set(this.activeData, name, isNumberStr(val) ? +val : val);
      }
    },
    setTimeValue(val, type) {
      const valueFormat = type === 'week' ? this.dateTimeFormat.date : val;
      this.$set(this.activeData.__config__, 'defaultValue', null);
      this.$set(this.activeData, 'value-format', valueFormat);
      this.$set(this.activeData, 'format', val);
    },
    spanChange(val) {
      this.formConf.span = val;
    },
    multipleChange(val) {
      this.$set(this.activeData.__config__, 'defaultValue', val ? [] : '');
    },
    dateTypeChange(val) {
      this.setTimeValue(this.dateTimeFormat[val], val);
    },
    rangeChange(val) {
      this.$set(
        this.activeData.__config__,
        'defaultValue',
        val ? [this.activeData.min, this.activeData.max] : this.activeData.min,
      );
    },
    rateTextChange(val) {
      if (val) this.activeData['show-score'] = false;
    },
    rateScoreChange(val) {
      if (val) this.activeData['show-text'] = false;
    },
    colorFormatChange(val) {
      this.activeData.__config__.defaultValue = null;
      this.activeData['show-alpha'] = val.indexOf('a') > -1;
      this.activeData.__config__.renderKey = +new Date(); // 更新renderKey,重新渲染该组件
    },
    openIconsDialog(model) {
      this.iconsVisible = true;
      this.currentIconModel = model;
    },
    setIcon(val) {
      this.activeData[this.currentIconModel] = val;
    },
    tagChange(tagIcon) {
      let target = inputComponents.find((item) => item.__config__.tagIcon === tagIcon);
      if (!target) target = selectComponents.find((item) => item.__config__.tagIcon === tagIcon);
      this.$emit('tag-change', target);
    },
    changeRenderKey() {
      this.activeData.__config__.renderKey = +new Date();
    },
  },
};
</script>

<style lang="scss" scoped>
.center-tabs {
  padding-left: 10px;
  box-sizing: border-box;
}
.right-board {
  width: 350px;
  position: absolute;
  right: 0;
  top: 0;
  padding-top: 3px;
  .field-box {
    position: relative;
    height: calc(100vh - 42px);
    box-sizing: border-box;
    overflow: hidden;
  }
  .el-scrollbar {
    height: 100%;
  }
}
.select-item {
  display: flex;
  border: 1px dashed #fff;
  box-sizing: border-box;
  & .close-btn {
    cursor: pointer;
    color: #f56c6c;
  }
  & .el-input + .el-input {
    margin-left: 4px;
  }
}
.select-item + .select-item {
  margin-top: 4px;
}
.select-item.sortable-chosen {
  border: 1px dashed #409eff;
}
.select-line-icon {
  line-height: 32px;
  font-size: 22px;
  padding: 0 4px;
  color: #777;
}
.option-drag {
  cursor: move;
}
.time-range {
  .el-date-editor {
    width: 227px;
  }
  ::v-deep .el-icon-time {
    display: none;
  }
}
.document-link {
  position: absolute;
  display: block;
  width: 26px;
  height: 26px;
  top: 0;
  left: 0;
  cursor: pointer;
  background: #409eff;
  z-index: 1;
  border-radius: 0 0 6px 0;
  text-align: center;
  line-height: 26px;
  color: #fff;
  font-size: 18px;
}
.node-label {
  font-size: 14px;
}
.node-icon {
  color: #bebfc3;
}
</style>
